//////////////////////////////////////////////////////////////////
// MattiseOS Kernel
// Date: 2008
// Author: Matthew Iselin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////

// Includes
#include <mattise.h>
#include <stdint.h>
#include <mem/util.h>
#include <screen/conio.h>
#include <kernio/common.h>

// Functions

// the helper function for printf (ie, what the formatter calls)
int printf_helper( uint8_t c, void** UNUSED(ptr) )
{
    // write the character
    kWriteChar( c, 0x0F );
    return 0;
}

// the printf formatter call function
int printf_format( const char* fmt, va_list args )
{
    // print it all
    return formatted_out_do( fmt, args, printf_helper, 0 );
}

// wrapper for the above
int printf( const char* fmt, ... )
{
    // setup the argument list
    va_list args;
    va_start( args, fmt );

    // this will hold the number of characters printed
    int rv = 0;

    // print!
    rv = printf_format( fmt, args );

    // end the argument list loading
    va_end( args );

    // return the number of characters read
    return rv;
}
